package com.um.login.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cs.framework.common.util.CommonUtils;
import com.um.info.dto.base.UmUserDto;
import com.um.info.service.UmUserService;
import com.um.login.service.LoginService;

/**
 * UM登陆
 * 
 * @author hedongzhou
 * 
 */
@Service("loginService")
public class LoginServiceImpl implements LoginService {

	@Resource
	private UmUserService umUserService;

	/**
	 * 用户登陆验证
	 * 
	 * @param umUserDto
	 *            用户信息
	 * @return 当前用户所有信息
	 */
	public UmUserDto checkLogin(UmUserDto umUserDto) {
		CommonUtils.throwNull(umUserDto.getUserId(), "用户名");
		CommonUtils.throwNull(umUserDto.getPassword(), "密码");

		UmUserDto entity = umUserService.get(umUserDto.getUserId());

		if (entity == null) {
			CommonUtils.throwRun("用户名不存在");
		}

		if (!"Y".equals(entity.getValid())) {
			CommonUtils.throwRun("该用户以失效");
		}

		if (!entity.getPassword().equals(umUserDto.getPassword())) {
			CommonUtils.throwRun("密码有误");
		}

		return entity;
	}
}
